package com.example.hrmsaas.company.controller;


import com.example.hrmsaas.company.service.ICompanyService;
import com.example.hrmsaas.company.vo.CompanyVo;
import com.example.hrmsaas.system.utils.DataGridView;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 雷哥
 * @since 2021-10-28
 */
@CrossOrigin(origins = {"http://localhost:4901", "null"})
@RestController
@RequestMapping("/company")
public class CompanyController {
    private Log log = (Log) LogFactory.getLog(CompanyController.class);

    @Autowired
    ICompanyService companyService;

    @RequestMapping("getCompanyList")
    public DataGridView getMenuList(HttpServletRequest request) throws ParseException {
        CompanyVo companyVo=new CompanyVo();
        Integer page = request.getParameter("page")!=null?Integer.valueOf(request.getParameter("page")):1;
        Integer limit = request.getParameter("limit") !=null?Integer.valueOf(request.getParameter("limit")):10;
        CompanyVo companyVoQueryMapper = this.getCompanyVoQueryMapper(companyVo,page,limit);
        return companyService.getCompanyAll(companyVoQueryMapper);
    }

    public CompanyVo getCompanyVoQueryMapper(CompanyVo companyVo,Integer page ,Integer limit)
    {
        companyVo.setPage(page);
        companyVo.setLimit(limit);
        return  companyVo;
    }


    @RequestMapping("getCompanyInfo")
    public DataGridView getCompanyInfo(HttpServletRequest request) throws ParseException
    {
        try {
            CompanyVo companyVo=new CompanyVo();
            String id = request.getParameter("id")!=null?request.getParameter("id"):null;
            if(null != id){
                companyVo.setId(id);
                return companyService.getCompanyOne(companyVo);
            }else{
                return new DataGridView();
            }
        }catch (Exception e){
            log.error(e.getMessage());
            return new DataGridView();
        }
    }
}

